<?php

$nro_ingresado = $_GET["nro_ingresado"];

//Me conecto a la base MySQL
define('__ROOT__', dirname(__FILE__));
require_once(__ROOT__ . '/connection.php');

$query = "SELECT Estados.descripcion AS estado,
					 DATE_FORMAT(OrdenHistorico.timestamp,'%d/%m/%Y') AS fecha_recortada, 
					 Tecnicos.nombre AS tecnico, 
					 OrdenHistorico.detalles 
			  FROM OrdenHistorico, Estados, Tecnicos
			  WHERE OrdenHistorico.nro_interno = '" . $nro_ingresado . "' 
			  	AND OrdenHistorico.estado_cod = Estados.estado_cod
				AND OrdenHistorico.tecnico_cod = Tecnicos.tecnico_cod
			  ORDER BY OrdenHistorico.timestamp
			  ;";
$result = $mysql->query($query);

echo "<table border='1'>
	<tr>
		<th>Item</th>
		<th>Estado</th>
		<th>Fecha</th>
		<th>Atendido</th>
		<th>Detalles</th>
	</tr>";

$i = 1;
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
    echo "<tr>";
    echo "<td>" . $i . "</td>";
    echo "<td>" . $row['estado'] . "</td>";
    echo "<td>" . $row['fecha_recortada'] . "</td>";
    echo "<td>" . $row['tecnico'] . "</td>";
    echo "<td><input type=\"text\" value=\"" . $row['detalles'] . "\" size=\"50\" readonly=\"true\"></input></td>";
    echo "</tr>";

    $i++;
}
echo "</table>";
$result->free;
$mysql->close;
?>
